<?php 
echo $this->Form->create("Payroll", array('action' => 'process_mail'));
echo $this->Form->hidden("Payroll.batch_list_id", array('value' => $batchData['BatchList']['id']));
?>
<table cellpadding="5">
    <tr>
        <td style="text-align: right; font-weight: bold;"><?php echo __('FROM')?> :</td>
        <td><?php echo $currentUserDetails['User']['e_name'];?></td>
        <td><?php echo __('ROLE');?> :</td>
        <td colspan="2"><?php echo empty($currentUserDetails['User']['role_id']) ? 'Admin' : $userRoles[$currentUserDetails['User']['role_id']];?></td>
    </tr>
    <tr>
        <td colspan="5">&nbsp;</td>
    </tr>
    <tr>
        <td style="text-align: right; font-weight: bold;"><?php echo __('TO')?> :</td>
        <td><?php echo __('RECIPIENTS')?> </td>
        <td><?php echo __('SELECT');?></td>
        <td><?php echo __('ROLE');?></td>
        <td><?php echo __('LEAVE_STATUS')?></td>
    </tr><?php  if(!empty($usersInServiceUnit)){ $i = 0; foreach($usersInServiceUnit as $users){?>
    <tr>
        <td>&nbsp;</td>
        <td><?php echo $users['User']['e_name'];?></td>
        <td><?php echo $this->Form->input('Payroll.receiver.', array('id' => 'receiver_'.$i, 'type' => 'checkbox', 'value' => $users['User']['id'], 'multiple' => TRUE, 'hiddenField' => false));?></td>
        <td><?php echo $userRoles[$users['User']['role_id']];?></td>
        <td><?php echo ($users['User']['on_leave'] == 1) ? __('ON_LEAVE') : '';?></td>
    </tr><?php $i++; }} else {?>
    <tr>
        <td colspan="5"><?php __('NO_USER_ALLOCATED');?></td>
    </tr> <?php } ?>
    <tr>
        <td colspan="5">&nbsp;</td>
    </tr>
    <tr>
        <td style="text-align: right; font-weight: bold;"><?php echo __('SUBJECT')?> :</td>
        <td colspan="4"><?php echo $batchData['ServiceUnit']['unit_code'];?> part time payroll (from <?php echo  empty($currentUserDetails['User']['role_id']) ? 'Admin' : $userRoles[$currentUserDetails['User']['role_id']];?>)</td>
    </tr>
    <tr>
        <td style="text-align: right; font-weight: bold;"><?php echo __('MESSAGE')?> :</td>
        <td colspan="4"><?php echo $this->Form->input('Payroll.message', array('type' => 'select', 'options' => $messageOptions, 'label' => FALSE, 'style' =>'width:100%'));?></td>
    </tr>
    <tr>
        <td style="text-align: right; font-weight: bold;"><?php echo __('REMARK')?> :</td>
        <td colspan="4"><?php echo $this->Form->input('Payroll.remark', array('type' => 'textarea', 'label' => FALSE, 'style' =>'resize:none; width:98%'));?></td>
    </tr>
    <tr>
        <td style="text-align: center;" colspan="5">
            <?php 
                echo $this->Form->submit(__('SEND', true), array(
                    "class" => "button", 
                    'label' => false, 
                    'div' => false,
                    //'onclick'=>'return confirm("Are you sure to Send Email?")'
                ));
                echo '<div class="buttonEnding"></div>';
            ?>
        </td>
    </tr>
</table>
<?php echo $this->Form->end(); ?>
<script>
    $(document).ready(function() {
        $('#PayrollProcessMailForm').submit(function() {
            var fields = $(this).find('input[type="checkbox"]');
            if(!fields.is(":checked")){
                alert('You must select at least one Recipient!');
                return false; // The form will *not* submit
            } else{
                var confirmCheck = confirm("Are you sure to Send Email?");
                if(confirmCheck == true){
                    return true;
                } else{
                    return false; // The form will *not* submit
                }
            }
            return false;         
        });
    });
</script>
    
